package com.cxl.mapreduce._2serialize_flowsum;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author joyson
 * @create 2019-06-07-下午12:59
 */
public class FlowCountReducer extends Reducer<Text, FlowBean, Text, FlowBean> {
    Text k=new Text();
    FlowBean v=new FlowBean();
    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {
        long sum_upFlow = 0;
        long sum_downFlow = 0;
        for (FlowBean flowBean:values){
            sum_upFlow+=flowBean.getUpFlow();
            sum_downFlow+=flowBean.getDownFlow();
        }
        k.set(key);
        v.set(sum_upFlow,sum_downFlow);
        context.write(k,v);
    }
}
